package cc.dd.marketing.coupon.rule.checker;


import cc.dd.marketing.rule.base.RuleChecker;
import cc.dd.marketing.system.exception.base.BusinessException;
import cc.dd.marketing.system.exception.response.ResultCodeEnum;
import cc.dd.marketing.coupon.dto.CouponUseInnerReqDTO;
import cc.dd.marketing.coupon.rule.domain.CouponEndTimeRule;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 优惠券过期时间规则
 * @author dongsufeng
 * @date 2022/9/9 2:26 PM
 */
@Component
public class CouponEndTimeRuleChecker implements RuleChecker<CouponEndTimeRule, CouponUseInnerReqDTO> {

    @Override
    public Boolean validate(CouponEndTimeRule rule, CouponUseInnerReqDTO request) {
        if(rule.getRule().before(new Date())){
            throw new BusinessException(ResultCodeEnum.RULE_CHECK_FAIL.getCode(),"优惠券已过期");
        }
        return true;
    }
}
